﻿
using Dapper;
using HBase; 
using System.Collections.Generic;
using System.Data;
using System.Linq;
namespace hCommand
{
    /**
   *┌────────────────────────────────────────────────┐
   *│　描    述：Component                                                    
   *│　作    者：sgj                                              
   *│　版    本：1.0                                              
   *│　创建时间：2020/9/2 11:28:16                        
   *└────────────────────────────────────────────────┘
   **/
    public class ContinueInEngine<CS> : AbsTaskComp where CS : AbsCoreStock {
        public long paramId;
        public int stn;
        protected CoreTaskParam ctp;
        protected CS cs;
      

        protected override TransRes Execute() {
            ctp = getById<CoreTaskParam>(paramId);
            TransRes res = check( );
            if (!res.s) {
                return res;
            }
            
            CoreTask ct = getById<CoreTask>(ctp.taskId );
            cs = getById<CS>(ct.stockId)  ;
            if(cs == null ) {
                return new TransRes("stock 为空");
            }
            CoreWhLoc loc = selectLoc( cs);
            if( loc == null ) {
                return new TransRes("货位获取异常");
            }
            long paramTaskId = moveCoreTaskParam(ct.id ,stn ,( int ) loc.id);
        
            LocCoreUtil.UpdataWhLoc(this ,( int ) loc.id ,ct.goodDiff);

            return new TransRes();
        }

        protected virtual TransRes check() {
            List<CoreTaskParam> ctpList =query<CoreTaskParam>("select * from Core_Task_Param  where task_Id=@taskId", ctp);
            foreach (CoreTaskParam p in ctpList) {
                if (p.status < 4) {
                    return new TransRes("状态异常");
                }
            }
            return new TransRes();
        }

    }
}
